<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        class User{
           constructor (name){
               this.data={name};
           }
           set name(name){
               if((typeof name )=="string"){
                   this.data.name=name;
               }
               else{
                   throw new Error("名字不是字符串!!!");
               }
           }
           get name(){
               return `名字:${this.data.name}`;
           }
         
        }
         let  u =new User("唐玮");
        
        // u.name=25;//报错
        console.log(u.name);
     
      
    </script>
</body>
</html>